package com.ayf.payment.game.api.service.platform.impl;

import com.alibaba.fastjson.JSONObject;
import com.ayf.payment.game.api.channel.ehb.util.RSA;
import com.ayf.payment.game.api.channel.youka.util.YouKaSignUtil;
import com.ayf.payment.game.api.config.SystemInitialization;
import com.ayf.payment.game.api.dto.MerchantAccountOptions;
import com.ayf.payment.game.api.dto.criteria.OrderInfoCriteria;
import com.ayf.payment.game.api.dto.platform.MerchantCashOutBatchDTO;
import com.ayf.payment.game.api.dto.platform.MerchantCashOutCountDTO;
import com.ayf.payment.game.api.dto.platform.MerchantCashOutDTO;
import com.ayf.payment.game.api.dto.platform.MerchantSettleDTO;
import com.ayf.payment.game.api.dto.platform.MerchantSettleDayDTO;
import com.ayf.payment.game.api.dto.platform.SettleConfigDTO;
import com.ayf.payment.game.api.dto.platform.SubstitutePayConfigDTO;
import com.ayf.payment.game.api.dto.platform.criteria.MerchantCashOutCriteria;
import com.ayf.payment.game.api.dto.platform.criteria.MerchantCashOutPageCriteria;
import com.ayf.payment.game.api.entity.platform.MerchantCashOut;
import com.ayf.payment.game.api.exception.BasicRuntimeException;
import com.ayf.payment.game.api.exception.InvalidRequestException;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.platform.MerchantCashOutMapper;
import com.ayf.payment.game.api.service.MerchantAccountService;
import com.ayf.payment.game.api.service.MerchantConfigService;
import com.ayf.payment.game.api.service.MerchantRepository;
import com.ayf.payment.game.api.service.payment.EHBPaymentOnbehalfOfService;
import com.ayf.payment.game.api.service.payment.faka.util.FaKaSignUtil;
import com.ayf.payment.game.api.service.payment.huandong.util.HuanDongSignUtil;
import com.ayf.payment.game.api.service.payment.huyu.util.HuYuSignUtil;
import com.ayf.payment.game.api.service.payment.qcjh.util.QCJHSignUtil;
import com.ayf.payment.game.api.service.payment.wanw.util.WanWSignUtil;
import com.ayf.payment.game.api.service.platform.MerchantCashOutService;
import com.ayf.payment.game.api.service.platform.MerchantSettleService;
import com.ayf.payment.game.api.service.platform.SubstitutePayConfigService;
import com.ayf.payment.game.api.utils.CommonResult;
import com.ayf.payment.game.api.utils.DateUtils;
import com.ayf.payment.game.api.utils.MerchantSettleServiceChargeUtil;
import com.ayf.payment.game.api.utils.RandomStrUtils;
import com.swwx.charm.commons.lang.utils.BeanConvertUtils;
import com.swwx.charm.commons.lang.utils.LogPortal;
import com.swwx.charm.zookeeper.exception.GetLockFailedException;
import com.swwx.charm.zookeeper.exception.ReleaseLockFailedException;
import com.swwx.charm.zookeeper.lock.DistributedLock;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class MerchantCashOutServiceImpl implements MerchantCashOutService {

	@Resource
	private MerchantCashOutMapper merchantCashOutMapper;

	@Resource
	private MerchantSettleService merchantSettleService;

	@Resource
	private MerchantAccountService merchantAccountService;

	@Resource
	private MerchantConfigService merchantConfigService;

	@Resource
	private MerchantRepository merchantRepository;

	@Resource
	private SubstitutePayConfigService substitutePayConfigService;

	@Autowired
	private MerchantCashOutService merchantCashOutService;

	@Resource
	private EHBPaymentOnbehalfOfService ehbPaymentOnbehalfOfService;

	@Resource
	private SystemInitialization systemInitialization;

	@Autowired
	protected DistributedLock distributedLock;

	@Override
	public List<MerchantSettleDayDTO> selectMerchantSettleDay1(MerchantCashOutPageCriteria selectCriteria) {
		SettleConfigDTO settleConfigDTO = systemInitialization.settleConfigDTO();
		List<MerchantSettleDayDTO> list = merchantCashOutMapper.selectMerchantSettleD1(selectCriteria);
		list.forEach((merchantSettleDayDTO) -> {
			if (merchantSettleDayDTO.getSettleType() == 0) {
				merchantSettleDayDTO.setSellteFee(BigDecimal.ZERO);
			}
			else {
				BigDecimal merchantFee = MerchantSettleServiceChargeUtil.getServiceCharge(merchantSettleDayDTO.getMerchantId(), merchantSettleDayDTO.getSellteAmount(), settleConfigDTO.getFeeCustom());
				merchantSettleDayDTO.setSellteFee(merchantFee);
			}
			merchantSettleDayDTO.setOrderGenerateFmt(DateUtils.stringFormat(merchantSettleDayDTO.getOrderGenerateTimeIndex().toString(), "yyyyMMdd", "yyyy-MM-dd"));

		});
		return list;
	}

	@Override
	public List<MerchantSettleDayDTO> selectMerchantSettleDay0(MerchantCashOutPageCriteria selectCriteria) {
		List<MerchantSettleDayDTO> list = merchantCashOutMapper.selectMerchantSettleD0(selectCriteria);
		list.forEach((merchantSettleDayDTO) -> {
			merchantSettleDayDTO.setOrderGenerateFmt(DateUtils.stringFormat(merchantSettleDayDTO.getOrderGenerateTimeIndex().toString(), "yyyyMMdd", "yyyy-MM-dd"));
		});
		return list;
	}

	@Override
	public MerchantCashOutCountDTO countMerchantSettleDay(MerchantCashOutCriteria selectCriteria) {

		return merchantCashOutMapper.countMerchantSettleDay(selectCriteria);
	}

	//交易状态  1 拒绝付款 2 等待付款 3付款成功 4 付款失败  5 代付中   平台结算
	@Override
	public CommonResult merchantSettleDay1(String launchName, String operatorName, MerchantSettleDayDTO merchantSettleDayDTO, String traceId) throws ParameterException {
		if (merchantSettleDayDTO.getMerchantId() == null) {
			throw new ParameterException("商户ID不能为空");
		}
		if (merchantSettleDayDTO.getTradeNumber() == null) {
			throw new ParameterException("结算单号不能为空");
		}
		if (merchantSettleDayDTO.getSellteFee() == null) {
			throw new ParameterException("结算单号[" + merchantSettleDayDTO.getTradeNumber() + "]的手续费不能为空");
		}
		if (merchantSettleDayDTO.getNeedSettleAmt() == null) {
			throw new ParameterException("结算单号[" + merchantSettleDayDTO.getTradeNumber() + "]的结算金额不能为空");
		}
		if (merchantSettleDayDTO.getNeedSettleAmt().compareTo(merchantSettleDayDTO.getSellteAmount()) > 0) {
			throw new ParameterException("结算单号[" + merchantSettleDayDTO.getTradeNumber() + "]的结算金额[" + merchantSettleDayDTO.getNeedSettleAmt() + "]不能大于实际结算金额[" + merchantSettleDayDTO.getSellteAmount() + "]");
		}
		if (merchantSettleDayDTO.getNeedSettleAmt().compareTo(merchantSettleDayDTO.getSellteFee()) <= 0) {
			throw new ParameterException("结算单号[" + merchantSettleDayDTO.getTradeNumber() + "]的结算金额[" + merchantSettleDayDTO.getNeedSettleAmt() + "]必须大于手续费金额[" + merchantSettleDayDTO.getSellteFee() + "]");
		}
		CommonResult commonResult = new CommonResult();
		commonResult.setCode(200);
		commonResult.setMsg("提交成功");
		try {
			if (merchantSettleDayDTO.getNeedSettleAmt().compareTo(merchantSettleDayDTO.getSellteFee()) == 1) {
				MerchantSettleDayDTO db = merchantCashOutMapper.getMerchantSettleDTO(merchantSettleDayDTO.getTradeNumber());
				MerchantCashOut merchantCashOut = new MerchantCashOut();
				merchantCashOut.setMerchantId(merchantSettleDayDTO.getMerchantId());
				merchantCashOut.setAccountName(db.getAccountName());
				merchantCashOut.setSettleType(db.getSettleType());
				merchantCashOut.setBankName(db.getBankName());
				merchantCashOut.setFee(merchantSettleDayDTO.getSellteFee());
				merchantCashOut.setCardNo(db.getCardNo());
				merchantCashOut.setAmount(merchantSettleDayDTO.getNeedSettleAmt());
				merchantCashOut.setBankCity(db.getBankCity());
				merchantCashOut.setBankProvince(db.getBankProvince());
				merchantCashOut.setBankBranchName(db.getBankBranchName());
				merchantCashOut.setBankBranchNo(db.getBankBranchNo());
				BigDecimal actualAmount = merchantSettleDayDTO.getNeedSettleAmt().subtract(merchantSettleDayDTO.getSellteFee());
				merchantCashOut.setActualAmount(actualAmount);
				Date currentDate = DateUtils.getNowDate();
				String settleOrdeCreateStr = DateUtils.dateToString(currentDate, DateUtils.formatPattern_Short);
				String settleOrderNo = "Y" + settleOrdeCreateStr + RandomStrUtils.createRandom(true, 8);
				merchantCashOut.setSettleDate(db.getOrderGenerateTimeIndex());
				merchantCashOut.setTradeNumber(settleOrderNo);
				merchantCashOut.setOperatorName(operatorName);
				merchantCashOut.setLaunchName(launchName);
				merchantCashOut.setOperatorTime(currentDate);
				merchantCashOut.setCreateTime(currentDate);
				merchantCashOut.setTradeStatus((short) 2);
				merchantCashOut.setIsAtuoSettle(0);
				merchantCashOut.setCashOutType(db.getCashOutType());
				merchantCashOut.setSettleType(db.getSettleType());
				merchantCashOut.setSettleOrderOn(merchantSettleDayDTO.getTradeNumber());
				merchantCashOutMapper.insert(merchantCashOut);
				Integer settleStatus = Integer.valueOf(2); // 默认部分结算
				if (db.getSettledAmt().add(merchantSettleDayDTO.getNeedSettleAmt()).compareTo(merchantSettleDayDTO.getSellteAmount()) == 0) {
					settleStatus = Integer.valueOf(1); // 已结算
				}
				merchantSettleService.updateSettleAmtAndSettleStatusBySettleOrderNo(merchantSettleDayDTO.getTradeNumber(), merchantSettleDayDTO.getNeedSettleAmt(), settleStatus);
			}
			else {
				commonResult.setCode(-1);
				commonResult.setMsg("结算失败，结算手续费[" + merchantSettleDayDTO.getSellteFee() + "]必须小于结算金额[" + merchantSettleDayDTO.getNeedSettleAmt() + "]！");
			}
		} catch (ParameterException e) {
			commonResult.setCode(-1);
			commonResult.setMsg("该订单已结算或数据不存在！");
		} catch (Exception e) {
			LogPortal.error("{} D1结算失败，发生{}异常原因:{}", e, traceId, e.getClass().getName(), e.getMessage());
			throw new ParameterException("结算失败，请联系技术支持，错误码：" + traceId);
		}
		return commonResult;
	}

	@Override
	public CommonResult merchantSettleManual(String launchName, MerchantSettleDayDTO merchantSettleDayDTO, String traceId) throws ParameterException {
		CommonResult commonResult = new CommonResult();
		commonResult.setCode(200);
		commonResult.setMsg("提交成功");
		try {
			MerchantSettleDayDTO merchantSettleDayDb = getMerchantSettleData(merchantSettleDayDTO.getMerchantId());
			if (merchantSettleDayDb == null) {
				commonResult.setCode(-1);
				commonResult.setMsg("{" + merchantSettleDayDTO.getMerchantId() + "}用户信息请完善提现信息");
				return commonResult;
			}

			if (merchantSettleDayDb.getSellteAmount().compareTo(merchantSettleDayDTO.getSellteAmount()) == -1) {
				commonResult.setCode(-1);
				commonResult.setMsg("提现失败,提现金额不能大于可提现金额！");
				return commonResult;
			}
			MerchantCashOut merchantCashOut = new MerchantCashOut();
			merchantCashOut.setMerchantId(merchantSettleDayDTO.getMerchantId());
			merchantCashOut.setAccountName(merchantSettleDayDb.getAccountName());
			merchantCashOut.setSettleType(merchantSettleDayDb.getSettleType());
			merchantCashOut.setBankName(merchantSettleDayDb.getBankName());
			merchantCashOut.setFee(merchantSettleDayDTO.getSellteFee());
			merchantCashOut.setCardNo(merchantSettleDayDb.getCardNo());
			merchantCashOut.setAmount(merchantSettleDayDTO.getSellteAmount());
			merchantCashOut.setBankCity(merchantSettleDayDb.getBankCity());
			merchantCashOut.setBankBranchName(merchantSettleDayDb.getBankBranchName());
			merchantCashOut.setBankProvince(merchantSettleDayDb.getBankProvince());
			merchantCashOut.setBankBranchNo(merchantSettleDayDb.getBankBranchNo());
			BigDecimal actualAmount = merchantSettleDayDTO.getSellteAmount().subtract(merchantSettleDayDTO.getSellteFee());
			merchantCashOut.setActualAmount(actualAmount);
			Date currentDate = DateUtils.getNowDate();
			String settleOrdeCreateStr = DateUtils.dateToString(currentDate, DateUtils.formatPattern_Short);
			String settleOrderNo = "Y" + settleOrdeCreateStr + RandomStrUtils.createRandom(true, 8);
			merchantCashOut.setSettleDate(Integer.parseInt(settleOrdeCreateStr));
			merchantCashOut.setTradeNumber(settleOrderNo);
			merchantCashOut.setOperatorName("");
			merchantCashOut.setLaunchName(launchName);
			merchantCashOut.setOperatorTime(currentDate);
			merchantCashOut.setCreateTime(currentDate);
			merchantCashOut.setTradeStatus((short) 0);
			merchantCashOut.setIsAtuoSettle(1);
			merchantCashOut.setCashOutType(1);
			merchantCashOut.setSettleOrderOn("-");
			merchantCashOut.setBatchTime(currentDate);
			merchantCashOutMapper.insert(merchantCashOut);
			MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
			merchantAccountOptions.setOptionType("提现");
			merchantAccountOptions.setFreezing(BigDecimal.ZERO);
			merchantAccountOptions.setCashWithdrawal(merchantSettleDayDTO.getSellteAmount().negate());
			merchantAccountOptions.setMerchantId(merchantSettleDayDTO.getMerchantId());
			merchantAccountOptions.setCashWithdrawalIng(merchantSettleDayDTO.getSellteAmount());
			merchantAccountService.updateMerchantAccount(merchantAccountOptions);
		} catch (Exception e) {
			LogPortal.error("{} 商户{}提现失败,发生{}异常:{}", e, traceId, merchantSettleDayDTO.getMerchantId(), e.getClass().getName(), e.getMessage());
			throw new ParameterException("提现提交失败，请联系技术支持,错误码：" + traceId);
		}
		return commonResult;
	}

	@Override
	public List<MerchantCashOutDTO> selectMerchantCashOutAll(MerchantCashOutPageCriteria selectCriteria) {

		return merchantCashOutMapper.selectMerchantCashOutAll(selectCriteria);
	}

	@Override
	public List<MerchantCashOutDTO> selectMerchantCashOutAllNoPage(MerchantCashOutCriteria selectCriteria) {
		return merchantCashOutMapper.selectMerchantCashOutAllNoPage(selectCriteria);
	}

	@Override
	public MerchantCashOutCountDTO countMerchantCashOutAll(MerchantCashOutCriteria selectCriteria) {
		return merchantCashOutMapper.countMerchantCashOutAll(selectCriteria);
	}

	@Override
	public List<MerchantCashOutBatchDTO> selectBatchOrderAll(MerchantCashOutPageCriteria selectCriteria) {
		return merchantCashOutMapper.selectBatchOrderAll(selectCriteria);
	}

	@Override
	public List<MerchantCashOutDTO> getCashOutByBatchList(MerchantCashOutCriteria selectCriteria) {
		return merchantCashOutMapper.getCashOutByBatchList(selectCriteria);

	}

	@Override
	public MerchantSettleDayDTO getMerchantSettleData(Integer merchantId) {
		return merchantCashOutMapper.getMerchantSettleData(merchantId);
	}

	@Override
	public void updatetradeStatus(String operatorName, String tradeNumber, int tradeStatus, int cashOutType, String traceId) throws ParameterException {
		try {
			MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(tradeNumber);
			if (null == merchantCashOut) {
				throw new ParameterException("审核失败，操作重复或订单不存在!");
			}
			if (merchantCashOut.getTradeStatus() == 0) {
				merchantCashOut.setCashOutType(cashOutType);
				merchantCashOut.setTradeStatus((short) tradeStatus);
				merchantCashOut.setOperatorName(operatorName);
				merchantCashOut.setOperatorTime(new Date());
				merchantCashOutMapper.updateByPrimaryKeySelective(merchantCashOut);
			}
			else {
				throw new ParameterException("审核失败，操作重复!");
			}
		} catch (ParameterException e) {
			throw new ParameterException(e.getMsg());
		} catch (Exception e) {
			LogPortal.error("{} 审核订单号{}审核失败,发生{}异常:{}", e, traceId, tradeNumber, e.getClass().getName(), e.getMessage());
			throw new ParameterException("审核失败，请联系技术支持,错误码：" + traceId);
		}
	}

	// 商户付款
	@Transactional
	public CommonResult merchantSettlePayment(String operatorName, String tradeNumber, String traceId, String settleBatchOrderNo, Date batchTime, String payChannelCode, Integer cashOutType, String tradePwd) {
		CommonResult commonResult = new CommonResult();
		commonResult.setCode(200);
		commonResult.setMsg("付款成功");
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(tradeNumber);
		if (null == merchantCashOut) {
			throw new InvalidRequestException("付款失败，操作重复或订单不存在！");
		}
		merchantCashOut.setBatchTime(batchTime);
		merchantCashOut.setBatcNumber(settleBatchOrderNo);
		merchantCashOut.setCashOutType(cashOutType);
		if (merchantCashOut.getTradeStatus() == 2 || merchantCashOut.getTradeStatus() == 0) {
			switch (cashOutType) {
				case 0:
					return settlePayment_1(operatorName, merchantCashOut, traceId);
				case 1:
					return settlePayment_3(operatorName, BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class), payChannelCode, tradePwd);
				case 2:
					return settlePayment_2(operatorName, merchantCashOut, traceId);
			}
		}
		else {
			commonResult.setCode(-1);
			commonResult.setMsg("付款失败，操作重复");
			return commonResult;
		}
		return commonResult;
	}

	//结算到流水
	@Transactional
	public CommonResult settlePayment_1(String operatorName, MerchantCashOut merchantCashOut, String traceId) {
		CommonResult commonResult = new CommonResult();
		commonResult.setCode(200);
		commonResult.setMsg("结算到可提现金额成功");
		try {
			MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
			if (merchantCashOut.getIsAtuoSettle() == 0) {
				merchantAccountOptions.setOptionType("结算付款");
				merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
			}
			else if (merchantCashOut.getIsAtuoSettle() == 2) {
				merchantAccountOptions.setOptionType("实时结算付款");
				merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
			}
			else {
				merchantAccountOptions.setOptionType("提现付款");
				merchantAccountOptions.setCashWithdrawalIng(merchantCashOut.getAmount().negate());
			}
			BigDecimal fee = merchantCashOut.getFee();
			fee = fee == null ? BigDecimal.ZERO : fee;
			merchantAccountOptions.setCashWithdrawal(merchantCashOut.getAmount().add(fee));
			merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
			merchantAccountService.updateMerchantAccount(merchantAccountOptions);
			merchantCashOut.setFee(BigDecimal.ZERO);
			merchantCashOut.setTradeStatus((short) 3);
			merchantCashOut.setOperatorName(operatorName);
			merchantCashOut.setOperatorTime(new Date());
			merchantCashOutMapper.updateByPrimaryKeySelective(merchantCashOut);
		} catch (Exception e) {
			LogPortal.error("{} 结算到可提现金额失败", e, traceId);
			throw new BasicRuntimeException(-1, "结算到可提现金额失败，错误码:" + traceId);
		}
		return commonResult;
	}

	//线下结算付款
	@Transactional
	public CommonResult settlePayment_2(String operatorName, MerchantCashOut merchantCashOut, String traceId) {
		CommonResult commonResult = new CommonResult();
		commonResult.setCode(200);
		commonResult.setMsg("线下结算付款成功");
		try {
			MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
			merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
			if (merchantCashOut.getIsAtuoSettle() == 0) {
				merchantAccountOptions.setOptionType("D+1结算付款");
				merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
				merchantAccountService.updateMerchantAccount(merchantAccountOptions);

				MerchantSettleDTO merchantSettleDTO = merchantSettleService.getMerchantSettleBySettleOrderNo(merchantCashOut.getSettleOrderOn());
				//已结算总金额
				BigDecimal settledAmt = merchantSettleDTO.getSettledAmt() == null ? BigDecimal.ZERO : merchantSettleDTO.getSettledAmt();
				if (settledAmt.compareTo(merchantSettleDTO.getMerchantSettleAmount()) == 0) {
					Integer settleStatus = Integer.valueOf(1);//已结算
					merchantSettleService.updateSettleAmtAndSettleStatusBySettleOrderNo(merchantCashOut.getSettleOrderOn(), BigDecimal.ZERO, settleStatus);
				}
			}
			else if (merchantCashOut.getIsAtuoSettle() == 2) {
				merchantAccountOptions.setOptionType("实时结算付款");
				merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
				merchantAccountService.updateMerchantAccount(merchantAccountOptions);
			}
			else {
				merchantAccountOptions.setCashWithdrawalIng(merchantCashOut.getAmount().negate());
				merchantAccountService.updateMerchantAccount(merchantAccountOptions);
			}
			merchantCashOut.setTradeStatus((short) 3);
			merchantCashOut.setOperatorName(operatorName);
			merchantCashOut.setOperatorTime(new Date());
			merchantCashOutMapper.updateByPrimaryKeySelective(merchantCashOut);
		} catch (Exception e) {
			LogPortal.error("{} 线下结算付款失败", e, traceId);
			throw new BasicRuntimeException(-1, "线下结算付款失败，错误码:" + traceId);
		}
		return commonResult;
	}

	//代付到账号
	@Transactional
	public CommonResult settlePayment_3(String operatorName, MerchantCashOutDTO merchantCashOut, String payChannelCode, String tradePwd) {
		CommonResult commonResult = ehbPaymentOnbehalfOfService.paymentOnbehalfOf(operatorName, merchantCashOut, payChannelCode, tradePwd);  //代付
		if (commonResult.getCode() == -1) {
			throw new InvalidRequestException(commonResult.getMsg());
		}
		return commonResult;
	}


	@Override
	public void updateRefuseMerchantPayment(String operatorName, String tradeNumber, String traceId) throws ParameterException {
		try {
			MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(tradeNumber);
			if (null == merchantCashOut) {
				throw new InvalidRequestException("拒绝付款失败，操作重复或订单不存在！");
			}
			if (merchantCashOut.getTradeStatus() == 2) {
				switch (merchantCashOut.getCashOutType()) {
					case 0:
						refuseMerchantPayment_1(operatorName, merchantCashOut);
						break;
					case 1:
						refuseMerchantPayment_2(operatorName, merchantCashOut);
						break;
					case 2:
						refuseMerchantPayment_2(operatorName, merchantCashOut);
						break;
				}
			}
			else {
				throw new InvalidRequestException("拒绝付款失败，操作重复");
			}
			merchantCashOut.setTradeStatus((short) 1);
			merchantCashOutMapper.updateByPrimaryKeySelective(merchantCashOut);
		} catch (InvalidRequestException e) {
			throw new ParameterException(e.getMsg());
		} catch (Exception e) {
			LogPortal.error("{} 商户订单号{}拒绝付款失败,发生{}异常:{}", e, traceId, tradeNumber, e.getClass().getName(), e.getMessage());
			throw new ParameterException("拒绝付款失败，请联系技术支持,错误码：" + traceId);
		}
	}

	@Override
	public void updateRefuseMerchantVerify(String operatorName, String tradeNumber, String traceId) throws ParameterException {
		try {
			MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(tradeNumber);
			if (null == merchantCashOut) {
				throw new ParameterException("拒绝提现失败，操作重复或订单不存在!");
			}
			if (merchantCashOut.getTradeStatus() == 0) {
				MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
				if (merchantCashOut.getIsAtuoSettle() == 2) { // 实时结算拒绝
					merchantAccountOptions.setOptionType("实时结算拒绝");
					merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
					merchantAccountOptions.setOptionCash(merchantCashOut.getAmount());
				}
				else if (merchantCashOut.getIsAtuoSettle() == 1) {
					merchantAccountOptions.setOptionType("拒绝提现");
					merchantAccountOptions.setCashWithdrawalIng(merchantCashOut.getAmount().negate());
					merchantAccountOptions.setCashWithdrawal(merchantCashOut.getAmount());
				}
				merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
				merchantAccountService.updateMerchantAccount(merchantAccountOptions);
				merchantCashOut.setTradeStatus((short) 7);
				merchantCashOutMapper.updateByPrimaryKeySelective(merchantCashOut);
			}
			else {
				throw new ParameterException("拒绝提现失败，操作重复!");
			}
		} catch (ParameterException e) {
			throw new ParameterException(e.getMsg());
		} catch (Exception e) {
			LogPortal.error("{} 商户提现订单号{}拒绝提现失败,发生{}异常:{}", e, traceId, tradeNumber, e.getClass().getName(), e.getMessage());
			throw new ParameterException("拒绝提现失败，请联系技术支持,错误码：" + traceId);
		}
	}

	@Transactional
	public void refuseMerchantPayment_1(String operatorName, MerchantCashOut merchantCashOut) {
		Example example = new Example(MerchantCashOut.class);
		example.createCriteria().andEqualTo("tradeNumber", merchantCashOut.getTradeNumber());
		merchantCashOutMapper.deleteByExample(example);
		merchantSettleService.updateMerchantSettleStatuByTradeNumber(merchantCashOut.getSettleOrderOn(), 0);
	}

	@Transactional
	public void refuseMerchantPayment_2(String operatorName, MerchantCashOut merchantCashOut) {
		if (merchantCashOut.getIsAtuoSettle() == 0) {
			Example example = new Example(MerchantCashOut.class);
			example.createCriteria().andEqualTo("tradeNumber", merchantCashOut.getTradeNumber());
			merchantCashOutMapper.deleteByExample(example);

			MerchantSettleDTO merchantSettleDTO = merchantSettleService.getMerchantSettleBySettleOrderNo(merchantCashOut.getSettleOrderOn());
			Integer settleStatus = Integer.valueOf(2);
			//已结算总金额
			BigDecimal settledAmt = merchantSettleDTO.getSettledAmt() == null ? BigDecimal.ZERO : merchantSettleDTO.getSettledAmt();
			if (settledAmt.compareTo(merchantCashOut.getAmount()) == 0) {
				settleStatus = Integer.valueOf(0);
			}
			merchantSettleService.updateSettleAmtAndSettleStatusBySettleOrderNo(merchantCashOut.getSettleOrderOn(), merchantCashOut.getAmount().negate(), settleStatus);
		}
		else if (merchantCashOut.getIsAtuoSettle() == 2) { // 实时结算拒绝付款
			MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
			merchantAccountOptions.setOptionType("实时结算拒绝付款");
			merchantAccountOptions.setOptionCash(merchantCashOut.getAmount());
			merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
			merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
			merchantAccountService.updateMerchantAccount(merchantAccountOptions);
		}
		else {
			MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
			merchantAccountOptions.setOptionType("拒绝付款");
			merchantAccountOptions.setFreezing(BigDecimal.ZERO);
			merchantAccountOptions.setCashWithdrawal(merchantCashOut.getAmount());
			merchantAccountOptions.setCashWithdrawalIng(merchantCashOut.getAmount().negate());
			merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
			merchantAccountService.updateMerchantAccount(merchantAccountOptions);
		}
	}

	@Override
	public boolean YHBpaymentOnbehalfOf(String traceId, String requestBody, String sign) {

		JSONObject plcyObject = JSONObject.parseObject(requestBody);
		JSONObject dataObject = JSONObject.parseObject(plcyObject.getString("data"));
		String orderId = dataObject.getString("merchant_order_no");
		if (StringUtils.isEmpty(orderId)) {
			LogPortal.info("{} 提现支付平台代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		String channelOrderStatus = dataObject.getString("status");
		if (!"FAIL".equals(channelOrderStatus) && !"SUCCESS".equals(channelOrderStatus)) {
			LogPortal.info("{} 提现支付平台代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderId, channelOrderStatus);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderId);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现支付平台代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderId);
			return true;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现支付平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderId, merchantCashOut.getTradeStatus(), channelOrderStatus);
			return true;
		}

		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		boolean result = RSA.verify(requestBody, sign, substitutePayConfigDTO.getEhbPayConfigParamVO().getChannelPubKey());
		if (result) {
			Date currentDate = DateUtils.getNowDate();
			merchantCashOut.setFinishTime(currentDate);
			if ("SUCCESS".equals(channelOrderStatus)) {
				agentPaySuccessDeal(merchantCashOut, currentDate);
			}
			else if ("FAIL".equals(channelOrderStatus)) {
				merchantCashOut.setTradeStatus((short) 4);
				merchantCashOut.setOperatorTime(currentDate);
				String failReason = dataObject.getString("err_code_desc");
				if (StringUtils.isEmpty(failReason)) {
					failReason = dataObject.getString("return_msg");
				}
				merchantCashOut.setReturnMsg(failReason);
				agentPayFailDeal(traceId, merchantCashOut);
				merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
			}
		}
		return true;
	}

	@Override
	public boolean WanXPaymentOnBehalfOf(String traceId, String status, String orderno) {
		if (StringUtils.isEmpty(orderno)) {
			LogPortal.info("{} 提现万象代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		if (!"3".equals(status) && !"2".equals(status)) {
			LogPortal.info("{} 提现万象代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderno, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderno);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现万象代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderno);
			return true;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现万象平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderno, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("2".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else if ("3".equals(status)) {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	/**
	 * 提现或结算接口代付成功业务处理
	 *
	 * @param merchantCashOut
	 * @param currentDate
	 */
	private void agentPaySuccessDeal(MerchantCashOut merchantCashOut, Date currentDate) {
		MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
		merchantAccountOptions.setOptionCash(BigDecimal.ZERO);
		merchantAccountOptions.setCashWithdrawal(BigDecimal.ZERO);
		if (merchantCashOut.getIsAtuoSettle() == 0 || merchantCashOut.getIsAtuoSettle() == 2) { // 结算
			merchantAccountOptions.setOptionType("结算成功");
			merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
		}
		else { // 提现
			merchantAccountOptions.setOptionType("提现成功");
			merchantAccountOptions.setCashWithdrawalIng(merchantCashOut.getAmount().negate());
		}
		merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
		merchantAccountService.updateMerchantAccount(merchantAccountOptions);
		merchantCashOut.setTradeStatus((short) 3);
		merchantCashOut.setOperatorTime(currentDate);
		merchantCashOut.setReturnMsg("--");
		merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		if (merchantCashOut.getIsAtuoSettle() == 0) {  //结算
			MerchantSettleDTO merchantSettleDTO = merchantSettleService.getMerchantSettleBySettleOrderNo(merchantCashOut.getSettleOrderOn());
			//已结算总金额
			BigDecimal settledAmt = merchantSettleDTO.getSettledAmt() == null ? BigDecimal.ZERO : merchantSettleDTO.getSettledAmt();
			if (settledAmt.compareTo(merchantSettleDTO.getMerchantSettleAmount()) == 0) {
				Integer settleStatus = Integer.valueOf(1);//已结算
				merchantSettleService.updateSettleAmtAndSettleStatusBySettleOrderNo(merchantCashOut.getSettleOrderOn(), BigDecimal.ZERO, settleStatus);
			}
		}
	}

	@Override
	public boolean LongBaoPaymentOnBehalfOf(String traceId, String status, String orderno, String desc) {
		if (StringUtils.isEmpty(orderno)) {
			LogPortal.info("{} 提现龙宝代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		if (!"S".equals(status) && !"F".equals(status)) {
			LogPortal.info("{} 提现龙宝代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderno, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderno);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现龙宝代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderno);
			return true;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现龙宝平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderno, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("S".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else if ("F".equals(status)) {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			merchantCashOut.setReturnMsg(desc);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean ZhuoFuTongPaymentOnBehalfOf(String traceId, String status, String orderNo, String desc) {
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现卓付通代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		if (!"SUCCESS".equals(status) && !"FAILED".equals(status)) {
			LogPortal.info("{} 提现卓付通代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现卓付通代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现卓付通平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("SUCCESS".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else if ("FAILED".equals(status)) {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			merchantCashOut.setReturnMsg(desc);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	/**
	 * 提现或结算接口代付失败，回退金额业务处理
	 *
	 * @param traceId
	 * @param merchantCashOut
	 */
	private void agentPayFailDeal(String traceId, MerchantCashOut merchantCashOut) {
		boolean lock = false;
		String lockName = System.getenv("XY_GAME_PAY_LOCK_FLAG").concat(merchantCashOut.getTradeNumber()).concat("agentPay");
		try {
			if (lock = distributedLock.getLock(lockName)) {

				if (merchantCashOut.getIsAtuoSettle() == 0) {  //结算
					MerchantSettleDTO merchantSettleDTO = merchantSettleService.getMerchantSettleBySettleOrderNo(merchantCashOut.getSettleOrderOn());
					Integer settleStatus = Integer.valueOf(2);
					//已结算总金额
					BigDecimal settledAmt = merchantSettleDTO.getSettledAmt() == null ? BigDecimal.ZERO : merchantSettleDTO.getSettledAmt();
					if (settledAmt.compareTo(merchantCashOut.getAmount()) == 0) {
						settleStatus = Integer.valueOf(0);
					}
					merchantSettleService.updateSettleAmtAndSettleStatusBySettleOrderNo(merchantCashOut.getSettleOrderOn(), merchantCashOut.getAmount().negate(), settleStatus);
				}
				else if (merchantCashOut.getIsAtuoSettle() == 2) { // 实时结算
					MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
					merchantAccountOptions.setOptionType("提现失败");
					merchantAccountOptions.setOptionCash(merchantCashOut.getAmount());
					merchantAccountOptions.setFreezing(merchantCashOut.getAmount().negate());
					merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
					merchantAccountService.updateMerchantAccount(merchantAccountOptions);
				}
				else { //GM可提现金额提现
					MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
					merchantAccountOptions.setOptionType("提现失败");
					merchantAccountOptions.setCashWithdrawal(merchantCashOut.getAmount());
					merchantAccountOptions.setCashWithdrawalIng(merchantCashOut.getAmount().negate());
					merchantAccountOptions.setMerchantId(merchantCashOut.getMerchantId());
					merchantAccountService.updateMerchantAccount(merchantAccountOptions);
				}
			}
		} catch (GetLockFailedException e) {
			LogPortal.error("{} >>> [DISTRIBUTED_LOCK_ACQUIRE_FAILED_ZK] 分布式锁获取失败,锁名称为:{}", traceId, lockName);
			LogPortal.error("{} >>> {} 获取lock失败", e, traceId, lockName);
		} catch (Exception e) {
			LogPortal.error("{} >>> {} 任务执行出错 ", e, traceId, lockName);
		} finally {
			if (lock) {
				LogPortal.info(traceId + " >>> " + lockName + " finished.");
				try {
					distributedLock.releaseLock(lockName);
				} catch (ReleaseLockFailedException e) {
					LogPortal.error("{} >>> [DISTRIBUTED_LOCK_RELEASE_FAILED_ZK] 分布式锁释放失败,锁名称为:{}", traceId, lockName);
					LogPortal.error("{} >>> {} 释放失败", e, traceId, lockName);
				}
			}
		}
	}

	@Override
	public Map<Integer, Map<String, Object>> selectSumWithdrawal(OrderInfoCriteria cri) {
		return merchantCashOutMapper.selectSumWithdrawal(cri);
	}

	@Override
	public void updateMerchantCashOut(MerchantCashOutDTO merchantCashOut) {
		merchantCashOutMapper.updateByPrimaryKeySelective(BeanConvertUtils.convert(merchantCashOut, MerchantCashOut.class));
	}

	@Override
	public MerchantCashOut getMerchantCashOutByTradeNumber(String tradeNumber) {
		Example example = new Example(MerchantCashOut.class);
		example.createCriteria().andEqualTo("tradeNumber", tradeNumber);
		return merchantCashOutMapper.selectOneByExample(example);
	}

	@Override
	public boolean updateMerchantCashOutByTradeNumber(MerchantSettleDayDTO merchantSettleDayDTO) {
		MerchantCashOut merchantCashOut = new MerchantCashOut();
		merchantCashOut.setBankBranchName(merchantSettleDayDTO.getBankBranchName());
		merchantCashOut.setBankCity(merchantSettleDayDTO.getBankCity());
		merchantCashOut.setBankName(merchantSettleDayDTO.getBankName());
		merchantCashOut.setAccountName(merchantSettleDayDTO.getAccountName());
		merchantCashOut.setCardNo(merchantSettleDayDTO.getCardNo());
		merchantCashOut.setSettleType(merchantSettleDayDTO.getSettleType());
		String tradeNumber = merchantSettleDayDTO.getTradeNumber();
		if (tradeNumber.length() > 17) {
			String str = tradeNumber.substring(17);
			tradeNumber = tradeNumber.substring(0, 17) + (Integer.parseInt(str) + 1);
		}
		else {
			tradeNumber = tradeNumber + "1";
		}
		merchantCashOut.setTradeNumber(tradeNumber);
		merchantCashOut.setTradeStatus((short) 2);
		Example example = new Example(MerchantCashOut.class);
		example.createCriteria().andEqualTo("tradeNumber", merchantSettleDayDTO.getTradeNumber());

		merchantCashOutMapper.updateByExampleSelective(merchantCashOut, example);
		merchantSettleDayDTO.setTradeNumber(tradeNumber);
		return true;
	}

	@Override
	public CommonResult realTimeWithdrawalApply(String launchName, MerchantSettleDayDTO merchantSettleDayDTO, String traceId) throws ParameterException {
		CommonResult commonResult = new CommonResult();
		commonResult.setCode(200);
		commonResult.setMsg("提交成功");
		try {
			MerchantSettleDayDTO merchantSettleDayDb = getMerchantSettleData(merchantSettleDayDTO.getMerchantId());
			if (merchantSettleDayDb == null) {
				commonResult.setCode(-1);
				commonResult.setMsg("{" + merchantSettleDayDTO.getMerchantId() + "}用户信息请完善结算信息");
				return commonResult;
			}
			if (merchantSettleDayDb.getBalance().compareTo(merchantSettleDayDTO.getSellteAmount()) == -1) {
				commonResult.setCode(-1);
				commonResult.setMsg("实时结算申请失败,金额不能大于可结算余额");
				return commonResult;
			}
			MerchantCashOut merchantCashOut = new MerchantCashOut();
			merchantCashOut.setMerchantId(merchantSettleDayDTO.getMerchantId());
			merchantCashOut.setAccountName(merchantSettleDayDb.getAccountName());
			merchantCashOut.setSettleType(merchantSettleDayDb.getSettleType());
			merchantCashOut.setBankName(merchantSettleDayDb.getBankName());
			merchantCashOut.setFee(merchantSettleDayDTO.getSellteFee());
			merchantCashOut.setCardNo(merchantSettleDayDb.getCardNo());
			merchantCashOut.setAmount(merchantSettleDayDTO.getSellteAmount());
			merchantCashOut.setBankCity(merchantSettleDayDb.getBankCity());
			merchantCashOut.setBankBranchName(merchantSettleDayDb.getBankBranchName());
			merchantCashOut.setBankProvince(merchantSettleDayDb.getBankProvince());
			merchantCashOut.setBankBranchNo(merchantSettleDayDb.getBankBranchNo());
			BigDecimal actualAmount = merchantSettleDayDTO.getSellteAmount().subtract(merchantSettleDayDTO.getSellteFee());
			merchantCashOut.setActualAmount(actualAmount);
			Date currentDate = DateUtils.getNowDate();
			String settleOrdeCreateStr = DateUtils.dateToString(currentDate, DateUtils.formatPattern_Short);
			String settleOrderNo = "Y" + settleOrdeCreateStr + RandomStrUtils.createRandom(true, 8);
			merchantCashOut.setSettleDate(Integer.parseInt(settleOrdeCreateStr));
			merchantCashOut.setTradeNumber(settleOrderNo);
			merchantCashOut.setOperatorName("");
			merchantCashOut.setLaunchName(launchName);
			merchantCashOut.setOperatorTime(currentDate);
			merchantCashOut.setCreateTime(currentDate);
			merchantCashOut.setTradeStatus((short) 0);
			merchantCashOut.setIsAtuoSettle(2);// 0 平台结算 1 GM提现 2-实时结算申请
			merchantCashOut.setCashOutType(merchantSettleDayDTO.getCashOutType());
			merchantCashOut.setSettleOrderOn("-");
			merchantCashOutMapper.insert(merchantCashOut);
			MerchantAccountOptions merchantAccountOptions = new MerchantAccountOptions();
			merchantAccountOptions.setOptionType("实时结算申请");
			merchantAccountOptions.setOptionCash(merchantSettleDayDTO.getSellteAmount().negate());
			merchantAccountOptions.setMerchantId(merchantSettleDayDTO.getMerchantId());
			merchantAccountOptions.setFreezing(merchantSettleDayDTO.getSellteAmount());
			merchantAccountService.updateMerchantAccount(merchantAccountOptions);
		} catch (Exception e) {
			LogPortal.error("{} 商户{}实时结算申请失败,发生{}异常:{}", e, traceId, merchantSettleDayDTO.getMerchantId(), e.getClass().getName(), e.getMessage());
			throw new ParameterException("实时结算申请提交失败，请联系技术支持,错误码：" + traceId);
		}
		return commonResult;
	}

	@Override
	public boolean QiYiPaymentOnBehalfOf(String traceId, String status, String orderNo) {
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现奇异代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		// 成功-1，管理员驳回-2,失败-3
		if (!"3".equals(status) && !"2".equals(status) && !"1".equals(status)) {
			LogPortal.info("{} 提现奇异代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现奇异代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现奇异平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("1".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else if ("2".equals(status) || "3".equals(status)) {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			if ("2".equals(status)) {
				merchantCashOut.setReturnMsg("接口方:管理员驳回");
			}
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean WanWPaymentOnBehalfOf(String traceId, Map<String, String> reqParamMap) {
		String orderNo = reqParamMap.get("orderid");
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现玩玩代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		String status = reqParamMap.get("code");
		if (StringUtils.isEmpty(status) || "100".equals(status)) {
			LogPortal.info("{} 提现玩玩代付异步通知 订单号[{}]渠道状态[{}]为空或为处理中，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现玩玩代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		Map<String, String> signMap = new LinkedHashMap<>();
		signMap.put("version", reqParamMap.get("version"));
		signMap.put("cid", reqParamMap.get("cid"));
		signMap.put("orderid", reqParamMap.get("orderid"));
		signMap.put("money", reqParamMap.get("money"));
		signMap.put("tradeid", reqParamMap.get("tradeid"));
		signMap.put("code", reqParamMap.get("code"));
		signMap.put("time", reqParamMap.get("time"));
		String ownSign = WanWSignUtil.getSign(traceId, "玩玩代付异步通知", signMap, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(reqParamMap.get("sign"))) {
			LogPortal.error("{} 提现玩玩代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return false;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现玩玩代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("0".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOut.setReturnMsg(reqParamMap.get("err"));
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public MerchantCashOut getMerchantCashOutByChannelOrderNo(String channelOrderNo) {
		Example example = new Example(MerchantCashOut.class);
		example.createCriteria().andEqualTo("channelOrderNo", channelOrderNo);
		return merchantCashOutMapper.selectOneByExample(example);
	}

	@Override
	public boolean XingYouPaymentOnBehalfOf(String traceId, String status, String orderNo) {
		// 状态:0-待处理,1-处理中,2-成功,3-失败
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现星游代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		if (!"3".equals(status) && !"2".equals(status)) {
			LogPortal.info("{} 提现星游代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现星游代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现星游平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("2".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else if ("3".equals(status)) {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean YouKaPaymentOnBehalfOf(String traceId, String status, String orderno, String channelSign, String amount) {
		if (StringUtils.isEmpty(orderno)) {
			LogPortal.info("{} 提现优卡代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		if (!"0".equals(status) && !"1".equals(status) && !"2".equals(status)) {
			LogPortal.info("{} 提现优卡代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderno, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderno);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现优卡代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderno);
			return true;
		}

		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		String ownSign = YouKaSignUtil.getAgentPayNotifySign(traceId, orderno, status, amount, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(channelSign)) {
			LogPortal.error("{} 提现优卡代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderno);
			return false;
		}

		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现优卡平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderno, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("0".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else if ("1".equals(status) || "2".equals(status)) {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean HuanDongPaymentOnBehalfOf(String traceId, String status, String orderNo, Map<String, String> signMap, String channelSign) {
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现欢动代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		// status判断 SUCCESS说明代付成功,返回其他均为失败
		if (StringUtils.isEmpty(status)) {
			LogPortal.info("{} 提现欢动代付异步通知 订单号[{}]渠道状态[{}]，渠道状态不是成功或失败，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现欢动代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		String ownSign = HuanDongSignUtil.getPaySign(traceId, "欢动代付异步通知", signMap, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(channelSign)) {
			LogPortal.error("{} 提现欢动代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return false;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现欢动平台代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("SUCCESS".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOut.setReturnMsg("接口方返回失败");
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean qcjhPaymentOnBehalfOf(String traceId, Map<String, String> reqParamMap) {
		String orderNo = reqParamMap.get("out_trade_no");
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现七彩聚合代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		// 0 表示成功，非0表示失败
		String status = reqParamMap.get("status");
		if (StringUtils.isEmpty(status)) {
			LogPortal.info("{} 提现七彩聚合代付异步通知 订单号[{}]渠道状态[{}]为空或为处理中，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现七彩聚合代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		Map<String, String> signMap = new LinkedHashMap<>();
		signMap.put("custid", reqParamMap.get("custid"));
		signMap.put("out_trade_no", reqParamMap.get("out_trade_no"));
		signMap.put("time_end", reqParamMap.get("time_end"));
		String ownSign = QCJHSignUtil.getSign(traceId, "七彩聚合代付异步通知", signMap, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(reqParamMap.get("sign"))) {
			LogPortal.error("{} 提现七彩聚合代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return false;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现七彩聚合代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("0".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOut.setReturnMsg("渠道返回失败");
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean huYuPaymentOnBehalfOf(String traceId, Map<String, String> reqParamMap) {
		String orderNo = reqParamMap.get("batchnumber");
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现互娱代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		// 状态,1:出款成功,不为1时见错误说明
		String status = reqParamMap.get("status");
		if (StringUtils.isEmpty(status)) {
			LogPortal.info("{} 提现互娱代付异步通知 订单号[{}]渠道状态[{}]为空或为处理中，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现互娱代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		Map<String, String> signMap = new LinkedHashMap<>();
		signMap.put("version", reqParamMap.get("version"));
		signMap.put("partner", reqParamMap.get("partner"));
		signMap.put("batchnumber", reqParamMap.get("batchnumber"));
		signMap.put("status", reqParamMap.get("status"));
		signMap.put("paymoney", reqParamMap.get("paymoney"));
		signMap.put("sysnumber", reqParamMap.get("sysnumber"));
		String ownSign = HuYuSignUtil.getSign(traceId, "互娱代付异步通知", signMap, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(reqParamMap.get("sign"))) {
			LogPortal.error("{} 提现互娱代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return false;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现互娱代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("1".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOut.setReturnMsg(reqParamMap.get("message"));
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public void updateSettleAgentPayOrderStatus(MerchantCashOutDTO merchantCashOutDTO) {
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(merchantCashOutDTO.getTradeNumber());
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			return;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOutDTO.setFinishTime(currentDate);
		if (merchantCashOutDTO.getTradeStatus() == null) {
			return;
		}
		if (StringUtils.isEmpty(merchantCashOut.getChannelOrderNo()) && StringUtils.isNotEmpty(merchantCashOutDTO.getChannelOrderNo())) {
			merchantCashOut.setChannelOrderNo(merchantCashOutDTO.getChannelOrderNo());
		}
		if (merchantCashOutDTO.getTradeStatus().intValue() == 3) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(merchantCashOutDTO.getTraceId(), merchantCashOut);
			merchantCashOut.setReturnMsg(merchantCashOutDTO.getReturnMsg());
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
	}

	@Override
	public boolean faKaPaymentOnBehalfOf(String traceId, Map<String, String> reqParamMap) {
		String orderNo = reqParamMap.get("requestId");
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现发卡代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		// 0 表示成功，非0表示失败
		String status = reqParamMap.get("status");
		if (StringUtils.isEmpty(status)) {
			LogPortal.info("{} 提现发卡代付异步通知 订单号[{}]渠道状态[{}]为空或为处理中，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现发卡代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		String ownSign = FaKaSignUtil.getSign(traceId, "发卡代付异步通知", reqParamMap, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(reqParamMap.get("code"))) {
			LogPortal.error("{} 提现发卡代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return false;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现发卡代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("SUCCESS".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOut.setReturnMsg("渠道返回失败");
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

	@Override
	public boolean sky98PaymentOnBehalfOf(String traceId, Map<String, String> reqParamMap) {
		String orderNo = reqParamMap.get("requestId");
		if (StringUtils.isEmpty(orderNo)) {
			LogPortal.info("{} 提现捷付通代付异步通知的商户订单号数值为空，不进行后续操作", traceId);
			return true;
		}
		// 0 表示成功，非0表示失败
		String status = reqParamMap.get("status");
		if (StringUtils.isEmpty(status)) {
			LogPortal.info("{} 提现捷付通代付异步通知 订单号[{}]渠道状态[{}]为空或为处理中，不进行后续操作", traceId, orderNo, status);
			return true;
		}
		MerchantCashOut merchantCashOut = getMerchantCashOutByTradeNumber(orderNo);
		if (merchantCashOut == null) {
			LogPortal.error("{} 提现捷付通代付异步通知 商户订单号[{}]在我方系统查询不到", traceId, orderNo);
			return true;
		}
		SubstitutePayConfigDTO substitutePayConfigDTO = substitutePayConfigService.getSubstitutePayConfigById(merchantCashOut.getPayChannelId());
		String ownSign = FaKaSignUtil.getSign(traceId, "捷付通代付异步通知", reqParamMap, substitutePayConfigDTO.getWanXiangPayConfigParamVO().getKey());
		if (!ownSign.equalsIgnoreCase(reqParamMap.get("code"))) {
			LogPortal.error("{} 提现捷付通代付异步通知 商户订单号[{}] 签名验证失败", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return false;
		}
		if (merchantCashOut.getTradeStatus() == 3 || merchantCashOut.getTradeStatus() == 4) {
			LogPortal.error("{} 提现捷付通代付异步通知 商户订单号[{}]状态已为终态，不用再更新订单状态，当前状态是[{}]，支付渠道推送过来的状态是[{}]", traceId, orderNo, merchantCashOut.getTradeStatus(), status);
			return true;
		}
		Date currentDate = DateUtils.getNowDate();
		merchantCashOut.setFinishTime(currentDate);
		if ("SUCCESS".equals(status)) {
			agentPaySuccessDeal(merchantCashOut, currentDate);
		}
		else {
			merchantCashOut.setTradeStatus((short) 4);
			merchantCashOut.setOperatorTime(currentDate);
			agentPayFailDeal(traceId, merchantCashOut);
			merchantCashOut.setReturnMsg("渠道返回失败");
			merchantCashOutService.updateMerchantCashOut(BeanConvertUtils.convert(merchantCashOut, MerchantCashOutDTO.class));
		}
		return true;
	}

}
